<?php

class Db_Tables_MembersWechat extends Zend_Db_Table
{
    protected $_name = 'members-wechat';
	var $member_id;
	var $open_id;
	var $head_image;
	var $gender;
	var $nick_name;
	
	function AddRecord()
	{
		$result = FALSE;
		
		if($this->member_id && $this->open_id)
		{
			$row = $this->fetchRow("member_id='".$this->member_id."' and open_id='".$this->open_id."'");
			
			if(!$row)
			{
				$new_row = $this->createRow();
				$new_row->member_id = $this->member_id;
				$new_row->open_id = $this->open_id;
				$new_row->ctime = date("Y-m-d H:i:s");
				
				if($new_row->save())
				{
					$result = TRUE;
				}
			}
		}
		
		return $result;
	}
	
	function UpdateWechatInfo()
	{
		$result = FALSE;
		
		$row = $this->fetchRow("open_id='".$this->open_id."'");
		
		if($row)
		{
			$mod_members = new Db_Tables_Members();
			$mod_members->member_id = $row->member_id;
			$mod_members->nick_name = $this->nick_name;
			$mod_members->gender = $this->gender;
			$mod_members->head_image = $this->head_image;
			$result = $mod_members->UpdateWechatInfo();
		}
		
		return $result;
	}
}